/**
 * 自定义公共函数
 */
var myfn = {};

/**
 * 系统相关信息
 * vk.myfn.systemInfo();
 */
myfn.systemInfo = function(){
	
	const sys = uni.getSystemInfoSync();
	const statusBarHeight = sys.statusBarHeight ? sys.statusBarHeight : 10;
	const topHeight = statusBarHeight + 44;
	const screenHeight = sys.screenHeight; //原生NavigationBar高度（含状态栏高度）+ 可使用窗口高度 + 原生TabBar高度
	const screenWidth = sys.screenWidth;
	const windowHeight = sys.windowHeight; //不包含NavigationBar和TabBar的高度
	const windowWidth = sys.windowWidth;
	const safeAreaHeight = sys.safeAreaInsets.bottom ? sys.safeAreaInsets.bottom : 10;
				
	return {
		statusBarHeight,
		topHeight,
		screenHeight,
		screenWidth,
		safeAreaHeight,
		windowHeight,
		windowWidth
	}
	
} 

/**
 * 是否隐藏home按钮
 * vk.myfn.hideHome();
 */
myfn.hideHome = function(){
	
	// 如果没有其他页面 则显示home
	if( getCurrentPages().length <= 1){
		return false;
	}
	
	return true;
	
}

/**
 * 页面返回逻辑
 */
myfn.pageBack = function(){
		
	if( getCurrentPages().length <= 1){
		uni.reLaunch({
			url: "/pages/index/index"
		});
	}else{
		uni.navigateBack();
	}
	
}

/**
 * 随机一个数
 */
myfn.getRandomInteger = function(min, max) {
	return Math.floor(Math.random() * (max - min + 1) + min ) ;
}

export default myfn;
